﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Linq;
using System.Collections.Generic;

namespace Tulde.WindowsPhone.Music
{
    /// <summary>
    /// A default view model caching implementation.
    /// This implementation simply adds items to a concurrent dictionary based on a key.
    /// </summary>
    public class DefaultViewModelCacheProvider : IViewModelCacheProvider
    {
        private Dictionary<object, object> dataCache;

        public DefaultViewModelCacheProvider()
        {
            this.dataCache = new Dictionary<object, object>();
        }

        #region IViewModelCacheProvider Members

        public void SetCacheItem(object key, object instance)
        {
            dataCache[key] = instance;
        }

        public T GetCacheItem<T>(object key)
        {
            return (T)dataCache[key];
        }

        public object GetCacheItem(object key)
        {
            return dataCache[key];
        }
        public bool CacheItemExists(object key)
        {
            try
            {
                return dataCache[key] != null ? true : false;
            }
            catch
            {
                return false;
            }
        }

        #endregion
    }
}
